/**
 * 专题图层 - 重要公共基础设施
 */
export default {
    data() {
        return {
        }
    },
    computed: {
        basin() {
            return this.$store.getters.basin
        }
    },
    watch: {
        basin: {
            handler: function(name) {
                this.$nextTick(() => {
                    this.creatZYGGJCSS()
                })
            },
            immediate: true
        }
    },
    created() {
        this.entitiesZYGGJCSS = []
    },
    methods: {
        creatZYGGJCSS() {
            if (this.layerList2[2].children.SHZHYSZQDC.children.ZYGGJCSS.show) {
                this.clearZYGGJCSS()
                var url = `${mapConfig.resUrlPre}/geojson/${this.basin}/ZYGGJCSS.json`
                this.$axios.get(url).then(res => {
                    // console.log(res.data)
                    // console.log(res.data.features)
                    
                    res.data.features.forEach((item) => {
                        var coordinates = item.geometry.coordinates
                        var entity = {
                            eventName: '重要公共基础设施',
                            lid: 'ZYGGJCSS',
                            prop: item.properties,
                            position: Cesium.Cartesian3.fromDegrees(
                                coordinates[0],
                                coordinates[1]
                            ),
                            billboard: {
                                image: this.layerList2[2].children.SHZHYSZQDC.children.ZYGGJCSS.icon,
                                horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
                                verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                                heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                                distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, this.$config.mapConfig.pb_far),
                                width: this.$config.mapConfig.billboardSize,
                                height: this.$config.mapConfig.billboardSize
                            }
                        }
                        this.entitiesZYGGJCSS.push(this.$viewer.entities.add(entity))
                    })
                    this.initEventZYGGJCSS()

                })
            } else {
                this.clearZYGGJCSS()
            }
        },
        initEventZYGGJCSS() {
            var eventFn = pickedObject => {
                if (
                    pickedObject &&
                    pickedObject.id &&
                    pickedObject.id.eventName
                ) {
                    if (pickedObject.id.eventName === '重要公共基础设施') {
                        const dlgParams = this.$store.getters.dlgParams
                        dlgParams.name = '重要公共基础设施'
                        dlgParams.remarks = pickedObject.id.prop
                        this.$store.dispatch('dlgParams', dlgParams)
                        console.log('重要公共基础设施',this.$store.getters.dlgParams)

                        this.$viewer.flyTo(pickedObject.id, {
                            duration: 0.5,
                            offset: {
                                heading: this.$viewer.camera.heading,
                                pitch: this.$viewer.camera.pitch,
                                range: 5000
                            }
                        })
                    }
                }
            }
            this.$store.getters.eventCesiumOption.leftPickFns.set('重要公共基础设施', eventFn)
        },
        clearZYGGJCSS() {
            if (this.entitiesZYGGJCSS && this.entitiesZYGGJCSS.length > 0) {
                this.entitiesZYGGJCSS.forEach(item => {
                    this.$viewer.entities.remove(item)
                })
                this.entitiesZYGGJCSS = []
            }
        },
        /**
         * 获取tip内容配置项
         * @param {Object} data 专题图层要素数据
         * @returns {Object}
         */
        getRemarksZYGGJCSS(data) {
            return [
                { name: null, value: data['O_Name'] }
                // { name: '房屋数', value: data.HOUSE },
                // { name: '人口数', value: data.PCOUNT },
            ]
        }
    }
}
